$(function () {
    $("#jqGrid").jqGrid({
        url: '../workDb/list',
        datatype: "json",
        colModel: [
            {label: 'id', name: 'id', width: 50, key: true},
            {label: '数据源唯一标识', name: 'dbKey', width: 80},
            {label: '名称', name: 'name', width: 80},
            {label: '数据库类型', name: 'dbType', width: 80},
            //{ label: '驱动类', name: 'driverClass', width: 80 },
            {label: '连接池', name: 'poolType', width: 80},
            //{ label: '连接类', name: 'poolClass', width: 80 },
            //{ label: '连接池选项(json格式)', name: 'poolOptions', width: 80 },
            //{ label: 'jdbcUrl', name: 'dbUrl', width: 80 },
            {label: 'dbName', name: 'dbName', width: 80},
            {label: '用户', name: 'dbUser', width: 80},
            //{ label: '密码', name: 'dbPassword', width: 80 }
        ],
        viewrecords: true,
        height: 800,
        rowNum: 20,
        rowList: [20, 30, 50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth: true,
        multiselect: true,
        pager: "#jqGridPager",
        jsonReader: {
            root: "page.data",
            page: "page.pageNo",
            total: "page.pageCount",
            records: "page.count"
        },
        prmNames: {
            page: "page",
            rows: "limit",
            order: "order"
        },
        gridComplete: function () {
            //隐藏grid底部滚动条
            //$("#jqGrid").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        isShowCond: true,
        btnText: '隐藏',
        qryForm: {
            name: ''
        }
    },
    methods: {
        reset: function () {
            this.qryForm.name = '';
        },
        query: function () {
            $("#jqGrid").jqGrid('setGridParam', {
                postData: {
                    name: vm.qryForm.name
                },
                page: 1
            }).trigger("reloadGrid");
        },
        toggle: function () {
            this.isShowCond = !this.isShowCond;

            if (this.isShowCond == true) {
                this.btnText = "隐藏"
            } else if (this.isShowCond == false) {
                this.btnText = "查询"
            }

        },
        update: function (event) {
            var id = getSelectedRow();
            if (id == null) {
                return;
            }

            location.href = "workDb_add.html?id=" + id;
        },

        del: function (event) {
            var ids = getSelectedRows();
            if (ids == null) {
                return;
            }

            confirm('确定要删除选中的记录？', function () {
                $.ajax({
                    type: "POST",
                    url: "../workDb/delete",
                    data: JSON.stringify(ids),
                    success: function (r) {
                        if (r.code == 0) {
                            alert('操作成功', function (index) {
                                $("#jqGrid").trigger("reloadGrid");
                            });
                        } else {
                            alert(r.msg);
                        }
                    }
                });
            });
        }
    }
});
